<?php

namespace app\admin\logic;
use app\admin\logic\BasicLogic;
use app\common\service\UploadService;
use app\common\service\CommonSystemImportService;
use app\data\util\MqQueueName;
use app\systems\logic\MqTaskPushLogic;
use app\admin\model\SmsRecordModel;
use app\admin\model\TestImportModel;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Log;
use app\common\library\RedissLock;
class TestTimeLogic extends BasicLogic
{

    /**
     * @desc  本地excel数据上传异步操作
     * @author luckyXiong
     * @Date   2024/03/20 10:55
     */
    public function uploadExcelTest($params){
        try{
            $result = CommonSystemImportService::staticModel()->operate_import_data([
                    $this,//当前对应的service
                    'save',//类型: template 下载模板; save :保存 导入
                    CommonSystemImportService::TYPE_IMPORT_INCOMPLETE_TIME,
                    1,
                    $params
                ]
            );
        }catch (\Exception $e) {
            return $this->jsonMessage(201, false, $e->getMessage(), null);
        }
    }


    /**
     * @desc 将导入数据写入目标表
     * @author xx
     * @date 2024-03-21
     */
    public function import_time_detail($params=[]){
        $key = 'import_time_detail:'.time();
        $redis_lock = new RedissLock();
        $lock = $redis_lock::lock($key, $redis_lock::UNBLOCK, 30);
        $order_id             = getIsset($params,'order_id');
        $create_time          = Db::name('info_operate')->where('order_id',$order_id)->value('createtime');
        //数据入库逻辑
        $info = [
            'order_id'           =>$order_id,
            'create_time'        =>date("Y-m-d", $create_time),
            'created_time'       =>date("Y-m-d H:i:s", time()),
        ];

        $res = Db::name('test_time')->insertGetId($info);
        $lock->unlock();
        $info['status'] = $res == 1 ? 1:2;
        return  $info;
    }


    /**
     * @param $row
     * @return string[]
     * @desc 数据title 导入组装数据结构
     */
    public function get_excel_row_data($row){
        return [
            'order_id'      => empty($row['A'])? '': trim($row['A']),
        ];
    }





}